package com.leyou.config;

import com.leyou.interceptor.AppTokenInterceptor;
import com.leyou.interceptor.UserTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 添加拦截器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private AppTokenInterceptor appTokenInterceptor;

    @Autowired
    private UserTokenInterceptor userTokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * addPathPatterns():添加拦截路径（黑名单）
         * excludePathPatterns():添加放行路径(白名单)
         */
        // registry.addInterceptor(拦截器).addPathPatterns(拦截路径)
        registry.addInterceptor(appTokenInterceptor).addPathPatterns("/**");
        registry.addInterceptor(userTokenInterceptor).addPathPatterns("/**");
    }
}
